package com.echo.util.jdbc;

import org.apache.commons.dbutils.QueryRunner;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

public class JdbcUtils {
    private   HikariDataSource dsWrite ;
	 private  static JdbcUtils  jdbcUtils;
    public JdbcUtils() {
		 HikariConfig config = new HikariConfig();
		 config.setMaximumPoolSize(10);
		 config.setMinimumIdle(2);
		 config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
		 config.addDataSourceProperty("serverName", "192.168.7.111");
		 config.addDataSourceProperty("port", "3306");
		 config.addDataSourceProperty("databaseName", "yiwei");
		 config.addDataSourceProperty("user", "root");
		 config.addDataSourceProperty("password", "123456");
		 //增加以下两行代码
		 config.addDataSourceProperty("useUnicode", "true");
		 config.addDataSourceProperty("characterEncoding", "utf8");	
		 config.setConnectionTestQuery("SELECT 1");
 
	      	  dsWrite = new HikariDataSource(config);
	}
	
    public   static  JdbcUtils  getJdbcUtilsInstall(){
    	
    	if(jdbcUtils==null){
    		synchronized (JdbcUtils.class) {
    			if(jdbcUtils==null)
    			jdbcUtils=	new  JdbcUtils();
			}
    	}
    	return jdbcUtils;
    }
	
    public  QueryRunner  getQueryRunner(){
    	return new QueryRunner(dsWrite);
    }
	
    public   java.sql.Connection  getConnection() throws Exception{
    	return   dsWrite.getConnection();
    }
}
